<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <script type="text/javascript" src="./layui/layui.js"></script>
    <script type="text/javascript" src="./javascript/jquery.min.js"></script>


</head>

<div class="layui-form-item" style="margin-top: 15px;">
    <label class="layui-form-label">周次：</label>
    <div class="layui-input-inline">
        <input type="text" id="week" name="week" lay-verify="num" value="1" placeholder="请输入" autocomplete="off"
            class="layui-input">
    </div>
    <label class="layui-form-label">教室名：</label>
    <div class="layui-input-inline">
        <input type="text" id="roomName" name="roomName" lay-verify="required" placeholder="模糊搜索" autocomplete="off"
            class="layui-input">
    </div>
    <a class="layui-btn layui-btn" id="find" lay-event="addTeaching" style="margin-left: 50px;">查询空教室</a>

</div>



<table class="layui-hide" id="demo" name="user" lay-data="{height: 'full-200', cellMinWidth: 80, page: true, limit:10}"
    lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
          <button class="layui-btn layui-btn-sm" lay-event="add">添加教室</button>
          <button class="layui-btn layui-btn-sm" lay-event="delete">删除教室</button>
        </div>
      </script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" id ="update" lay-event="edit">编辑</a>
  </script>
<script>


</script>
<script>
    var table;
 $(document).ready(function () {
            var patrn = /^\+?[1-9][0-9]*$/;
            $("#find").click(function () {
                var value = $("#week").val();
                if ($("#week").val() == "" || $("#week").val() == null) {
                    layer.msg("请输入周次");
                }else if(value = null || value.length == 0 || patrn.exec(value) == null || value > 20 || value < 1){
                    layer.msg("周次只能为1-20非空数字");
                    $("#week").val("");
                } else {
                    console.log("1111111")
                   reload();
                }
            });

        });

    //重新加载table
    function reload() {
        table.reload('demo', {
            url: "http://127.0.0.1:8088/classroom/findByWeek?week="+$("#week").val()+"&roomName="+$("#roomName").val()
        })
    }
    
    layui.use(['table' , 'layedit', 'laydate'], function () {
        table = layui.table //表格
        table.render({
            elem: '#demo'
            , url: 'http://127.0.0.1:8088/classroom/findByWeek?week=1' //数据接口
            , request: {
                pageName: 'pageNum' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.status, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.list //解析数据列表
                };
            }
            , title: '用户表'
            , page: true //开启分页
            , toolbar: 'false' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            , cols: [[ //表头
                { type: 'checkbox', fixed: 'left' }
                , { field: 'week', title: '周次', sort: true, fixed: 'left', align: "center" }
                , { field: 'classroomId', title: '教室id', sort: true, fixed: 'left', align: "center" }
                , { field: 'classroomName', title: '教室名字', align: "center" }
                , { field: 'day', title: '星期', sort: true, align: "center" }
                , { field: 'number', title: '节数', sort: true, align: "center" }
            ]]
        });
    });
</script>

<body>
</body>

</html>